{extend name="./_content"}
{block name='mid'}
<div class="jumbotron">
    <div class="container">
        <h1>登录</h1>
        <p>登录到系统</p>
        <p>
            <a class="btn btn-primary btn-lg" id="btn_login">登录</a>
        </p>
    </div>
</div>

<div class="well">
    <form action="" method="post" class="form-horizontal" role="form" id="login">
        <div class="form-group">
            <label class="col-sm-2 control-label ">用户名</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="name" name="name" placeholder="输入姓名" required data-bv-notempty-message="姓名不能为空" pattern="^.{2,10}$" data-bv-regexp-message="姓名在两到十个字之间"	/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">密码</label>
            <div class="col-sm-6">
                <input type="password" class="form-control" id="password" name="password" placeholder="输入密码" required
                       data-bv-notempty-message="密码姓名不能为空" pattern="^.{6,15}$" data-bv-regexp-message="密码在两到六到十五个字符之间"
                />
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
       view.init();
    });
    
    let view = {
        init:function () {
            $('#login').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                }
            });
            $('#btn_login').on('click',this.btn_login);
            $('#login').on('submit',function () {
                return false;
            });
        },
        btn_login:function () {
            $('#login').data('bootstrapValidator').validate();
            var b = $('#login').data('bootstrapValidator').isValid();
            if (!b){
                return false;
            }

            $('#btn_login').attr('disabled','disabled');
            $.ajax({
                url: '/index/user/login',
                type: 'post',
                dataType: 'json',
                data: $('#login').serialize(),
            })
            .done(function(data) {
                if (data.status === 1){
                    alert(data.msg);
                    wpgaci.goUrl('/index/user',0);
                }else{
                    alert(data.msg);
                    $('#btn_login').removeAttr('disabled');
                }
            })
            .fail(function() {
                console.log("error");
                $('#btn_login').removeAttr('disabled');

            });
        }
    }
</script>
{/block}